home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / moni / systemviewer.lha / AddAssign.c next >
C/C++ Source or Header  |  2001-02-12  |  9KB  |  382 lines

  1. /****h* SysAssigns/AddAssign.c [1.0] ********************************
  2. *
  3. * NAME
  4. *    AddAssign
  5. *
  6. * DESCRIPTION
  7. *    Get an Assignment string & a pathname from the User.
  8. * FUNCTIONAL INTERFACE:
  9. *
  10. *    PUBLIC int AddAssignment( void );
  11. *********************************************************************
  12. *
  13. */
  14.  
  15. #include <string.h>
  16.  
  17. #include <exec/types.h>
  18.  
  19. #include <intuition/intuition.h>
  20. #include <intuition/classes.h>
  21. #include <intuition/classusr.h>
  22. #include <intuition/gadgetclass.h>
  23.  
  24. #include <libraries/gadtools.h>
  25.  
  26. #include <graphics/displayinfo.h>
  27. #include <graphics/gfxbase.h>
  28.  
  29. #include <clib/exec_protos.h>
  30. #include <clib/intuition_protos.h>
  31. #include <clib/gadtools_protos.h>
  32. #include <clib/graphics_protos.h>
  33. #include <clib/utility_protos.h>
  34. #include <clib/diskfont_protos.h>
  35.  
  36. #include "CPGM:GlobalObjects/CommonFuncs.h"
  37.  
  38. #define StrBfPtr( g ) (((struct StringInfo *)g->SpecialInfo)->Buffer)
  39.  
  40. #define AssignStr 0
  41. #define PathStr   1
  42. #define OkayBt    2
  43. #define CancelBt  3
  44.  
  45. #define AAR_CNT   4
  46.  
  47. #define ASSIGN_STR StrBfPtr( AARGadgets[ AssignStr ] )
  48. #define PATH_STR   StrBfPtr( AARGadgets[ PathStr ] )
  49.  
  50. IMPORT struct Screen   *Scr;
  51. IMPORT struct TextAttr *Font;
  52. IMPORT struct CompFont  CFont;
  53.  
  54. IMPORT UBYTE           *PubScreenName;
  55. IMPORT APTR             VisualInfo;
  56. IMPORT char            *ErrMsg;
  57.  
  58. IMPORT struct IntuitionBase *IntuitionBase;
  59. IMPORT struct Library       *GadToolsBase;
  60.  
  61. // --------------------------------------------------------------------
  62.  
  63. PUBLIC char an[256], *assignname = &an[0];
  64. PUBLIC char pn[256], *pathname   = &pn[0];
  65.  
  66. // --------------------------------------------------------------------
  67.  
  68. PRIVATE struct TextFont     *AARFont  = NULL;
  69. PRIVATE struct Window       *AARWnd   = NULL;
  70. PRIVATE struct Gadget       *AARGList = NULL;
  71. PRIVATE struct IntuiMessage  AARMsg;
  72. PRIVATE struct Gadget       *AARGadgets[ AAR_CNT ];
  73.  
  74. PRIVATE UWORD  AARLeft   = 80;
  75. PRIVATE UWORD  AARTop    = 32;
  76. PRIVATE UWORD  AARWidth  = 415;
  77. PRIVATE UWORD  AARHeight = 80;
  78. PRIVATE UBYTE *AARWdt    = "Add an Assignment to the System:";
  79.  
  80.  
  81. PRIVATE UWORD AARGTypes[] = {
  82.  
  83.    STRING_KIND, STRING_KIND, BUTTON_KIND, BUTTON_KIND
  84. };
  85.  
  86. PRIVATE int AssignStrClicked( void );
  87. PRIVATE int PathStrClicked(   void );
  88. PRIVATE int OkayBtClicked(    void );
  89. PRIVATE int CancelBtClicked(  void );
  90.  
  91. PRIVATE struct NewGadget AARNGad[] = {
  92.  
  93.     72,  5, 301, 18, (UBYTE *) "_Assign:",  NULL, AssignStr, 
  94.    PLACETEXT_LEFT, NULL, (APTR) AssignStrClicked,
  95.  
  96.     72, 29, 301, 18, (UBYTE *) "_To Path:", NULL, PathStr, 
  97.    PLACETEXT_LEFT, NULL, (APTR) PathStrClicked,
  98.  
  99.     18, 54,  65, 18, (UBYTE *) "_OKAY",     NULL, OkayBt, 
  100.    PLACETEXT_IN, NULL, (APTR) OkayBtClicked,
  101.  
  102.    333, 54,  65, 18, (UBYTE *) "_CANCEL",   NULL, CancelBt, 
  103.    PLACETEXT_IN, NULL, (APTR) CancelBtClicked
  104. };
  105.  
  106. PRIVATE ULONG AARGTags[] = {
  107.  
  108.    (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGCENTER), 
  109.    (GT_Underscore), '_', (TAG_DONE),
  110.    
  111.    (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGCENTER), 
  112.    (GT_Underscore), '_', (TAG_DONE),
  113.    
  114.    (GT_Underscore), '_', (TAG_DONE),
  115.    (GT_Underscore), '_', (TAG_DONE)
  116. };
  117.  
  118. // --------------------------------------------------------------------
  119.  
  120. PRIVATE void CloseAARWindow( void )
  121. {
  122.    if (AARWnd != NULL) 
  123.       {
  124.       CloseWindow( AARWnd );
  125.       AARWnd = NULL;
  126.       }
  127.  
  128.    if (AARGList != NULL) 
  129.       {
  130.       FreeGadgets( AARGList );
  131.       AARGList = NULL;
  132.       }
  133.  
  134.    if (AARFont != NULL) 
  135.       {
  136.       CloseFont( AARFont );
  137.       AARFont = NULL;
  138.       }
  139.  
  140.    return;
  141. }
  142.  
  143. PRIVATE BOOL GotAssignStr = FALSE;
  144. PRIVATE BOOL GotPathStr   = FALSE;
  145.  
  146. PRIVATE int AssignStrClicked( void )
  147. {
  148.    strcpy( assignname, ASSIGN_STR );
  149.  
  150.    GotAssignStr = TRUE;
  151.  
  152.    return( (int) TRUE );
  153. }
  154.  
  155. PRIVATE int PathStrClicked( void )
  156. {
  157.    strcpy( pathname, PATH_STR );
  158.    
  159.    GotPathStr = TRUE;
  160.    
  161.    return( (int) TRUE );
  162. }
  163.  
  164. #define GOTASSIGN  2
  165.  
  166. PRIVATE int OkayBtClicked( void )
  167. {
  168.    if (GotAssignStr == FALSE)
  169.       {
  170.       SetReqButtons( "OKAY!" );
  171.       
  172.       (void) Handle_Problem( "Enter an Assignment first!",
  173.                              "User ERROR:", NULL
  174.                            );
  175.  
  176.       SetReqButtons( "CONTINUE|ABORT!" );
  177.       return( (int) TRUE );
  178.       }
  179.  
  180.    if (GotPathStr == FALSE)
  181.       {
  182.       SetReqButtons( "OKAY!" );
  183.       
  184.       (void) Handle_Problem( "Enter a Path to Assign to first!",
  185.                              "User ERROR:", NULL
  186.                            );
  187.  
  188.       SetReqButtons( "CONTINUE|ABORT!" );
  189.       return( (int) TRUE );
  190.       }
  191.  
  192.    CloseAARWindow();
  193.  
  194.    return( (int) GOTASSIGN );
  195. }
  196.  
  197. PRIVATE int CancelBtClicked( void )
  198. {
  199.    strcpy( assignname, "" );
  200.    strcpy( pathname,   "" );
  201.  
  202.    CloseAARWindow();
  203.  
  204.    return( (int) FALSE );
  205. }
  206.  
  207. PRIVATE int AARVanillaKey( int whichkey )
  208. {
  209.    int rval = TRUE;
  210.  
  211.    switch (whichkey)
  212.       {
  213.       case 'a':
  214.       case 'A':
  215.          rval = AssignStrClicked();
  216.          break;
  217.          
  218.       case 't':
  219.       case 'T':
  220.          rval = PathStrClicked();
  221.          break;
  222.          
  223.       case 'o':
  224.       case 'O':
  225.          rval = OkayBtClicked();
  226.          break;
  227.  
  228.       case 'c':
  229.       case 'C':
  230.       case 'q':
  231.       case 'Q':
  232.       case 'x':
  233.       case 'X':
  234.          rval = CancelBtClicked();
  235.  
  236.       default:
  237.          break;
  238.       }
  239.  
  240.    return( rval );
  241. }
  242.  
  243. PRIVATE int OpenAARWindow( void )
  244. {
  245.    struct NewGadget  ng;
  246.    struct Gadget    *g;
  247.    UWORD             lc, tc;
  248.    UWORD             wleft = AARLeft, wtop = AARTop, ww, wh;
  249.  
  250.    ComputeFont( Scr, Font, &CFont, AARWidth, AARHeight );
  251.  
  252.    ww = ComputeX( CFont.FontX, AARWidth );
  253.    wh = ComputeY( CFont.FontY, AARHeight );
  254.  
  255.    if ((wleft + ww + CFont.OffX + Scr->WBorRight) > Scr->Width) 
  256.       wleft = Scr->Width - ww;
  257.    
  258.    if ((wtop + wh + CFont.OffY + Scr->WBorBottom) > Scr->Height) 
  259.       wtop = Scr->Height - wh;
  260.  
  261.    if ((AARFont = OpenDiskFont( Font )) == NULL)
  262.       return( -5 );
  263.  
  264.    if ((g = CreateContext( &AARGList )) == NULL)
  265.       return( -1 );
  266.  
  267.    for (lc = 0, tc = 0; lc < AAR_CNT; lc++) 
  268.       {
  269.       CopyMem( (char *) &AARNGad[ lc ], (char *) &ng, 
  270.                (long) sizeof( struct NewGadget )
  271.              );
  272.  
  273.       ng.ng_VisualInfo = VisualInfo;
  274.       ng.ng_TextAttr   = Font;
  275.  
  276.       ng.ng_LeftEdge   = CFont.OffX + ComputeX( CFont.FontX, 
  277.                                                 ng.ng_LeftEdge
  278.                                               );
  279.  
  280.       ng.ng_TopEdge    = CFont.OffY + ComputeY( CFont.FontY, 
  281.                                                 ng.ng_TopEdge
  282.                                               );
  283.  
  284.       ng.ng_Width      = ComputeX( CFont.FontX, ng.ng_Width );
  285.       ng.ng_Height     = ComputeY( CFont.FontY, ng.ng_Height);
  286.  
  287.       AARGadgets[ lc ] = g = CreateGadgetA( (ULONG) AARGTypes[ lc ], 
  288.                                g, 
  289.                                &ng, 
  290.                                (struct TagItem *) &AARGTags[ tc ] );
  291.  
  292.       while (AARGTags[ tc ] != NULL) 
  293.          tc += 2;
  294.          
  295.       tc++;
  296.  
  297.       if (g == NULL)
  298.          return( -2 );
  299.       }
  300.  
  301.    if ((AARWnd = OpenWindowTags( NULL,
  302.  
  303.                    WA_Left,        wleft,
  304.                    WA_Top,         wtop,
  305.                    WA_Width,       ww + CFont.OffX + Scr->WBorRight,
  306.                    WA_Height,      wh + CFont.OffY + Scr->WBorBottom,
  307.  
  308.                    WA_IDCMP,       STRINGIDCMP | BUTTONIDCMP 
  309.                      | IDCMP_VANILLAKEY | IDCMP_REFRESHWINDOW,
  310.  
  311.                    WA_Flags,       WFLG_DRAGBAR | WFLG_DEPTHGADGET
  312.                      | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_RMBTRAP,
  313.  
  314.                    WA_Gadgets,     AARGList,
  315.                    WA_Title,       AARWdt,
  316.                    WA_ScreenTitle, "System Info:",
  317.                    TAG_DONE )
  318.       ) == NULL)
  319.       return( -4 );
  320.  
  321.    GT_RefreshWindow( AARWnd, NULL );
  322.  
  323.    return( 0 );
  324. }
  325.  
  326. PRIVATE int HandleAARIDCMP( void )
  327. {
  328.    struct IntuiMessage    *m;
  329.    int            (*func)( void );
  330.    BOOL            running = TRUE;
  331.  
  332.    while (running == TRUE)
  333.       {
  334.       if ((m = GT_GetIMsg( AARWnd->UserPort )) == NULL) 
  335.          {
  336.          (void) Wait( 1L << AARWnd->UserPort->mp_SigBit );
  337.          continue;
  338.          }
  339.  
  340.       CopyMem( (char *) m, (char *) &AARMsg, 
  341.                (long) sizeof( struct IntuiMessage )
  342.              );
  343.  
  344.       GT_ReplyIMsg( m );
  345.  
  346.       switch (AARMsg.Class) 
  347.          {
  348.          case IDCMP_REFRESHWINDOW:
  349.             GT_BeginRefresh( AARWnd );
  350.             GT_EndRefresh( AARWnd, TRUE );
  351.             break;
  352.  
  353.          case IDCMP_VANILLAKEY:
  354.             running = AARVanillaKey( AARMsg.Code );
  355.               break;
  356.  
  357.          case IDCMP_GADGETUP:
  358.             func = (void *) ((struct Gadget *)AARMsg.IAddress)->UserData;
  359.             
  360.             if (func != NULL)
  361.                running = func();
  362.             
  363.             break;
  364.          }
  365.       }
  366.  
  367.    return( running );
  368. }
  369.  
  370. PUBLIC int AddAssignment( void )
  371. {
  372.    if (OpenAARWindow() < 0)
  373.       {
  374.       return( -1 );
  375.       }
  376.       
  377.    return( HandleAARIDCMP() );
  378. }
  379.  
  380. /* --------------- END of AddAssign.c file! --------------------- */
  381.